/*
 *  Copyright (C) 2010 Zubanov Dmitry
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


/**
 *
 * @author Zubanov Dmitry aka javadimon, zubanov@gmail.com
 * Omsk, Russia, created 29.05.2010
 * (C) Copyright by Zubanov Dmitry
 */

package org.jssdb.core.josql;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.logging.Logger;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.LongValue;
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
import net.sf.jsqlparser.schema.Column;

public class WhereExpressionFinder extends WhereExpression {

    private static final Logger logger = Logger.getLogger(WhereExpressionFinder.class.getName());
    private Map map = new LinkedHashMap();

    public Map getExpressionMap(Expression e) {
        e.accept(this);
        return map;
    }

    @Override
    public void visit(AndExpression andExpression) {
        map.put("AndExpressionLeftExpression", andExpression.getLeftExpression());
        andExpression.getLeftExpression().accept(this);

        //map.put("AndExpressionRightExpression", andExpression.getRightExpression());
        //andExpression.getRightExpression().accept(this);
    }

    @Override
    public void visit(EqualsTo equalsTo) {
        map.put("EqualsToLeftExpression", equalsTo.getLeftExpression());
        equalsTo.getLeftExpression().accept(this);

        map.put("EqualsToRightExpression", equalsTo.getRightExpression());
        equalsTo.getRightExpression().accept(this);
    }

    @Override
    public void visit(Column tableColumn) {
        //map.put(tableColumn.getClass().getName(), tableColumn.getTable());
    }

    @Override
    public void visit(net.sf.jsqlparser.expression.StringValue stringValue) {
        map.put(stringValue.getClass().getName(), stringValue.getValue());
    }

    @Override
    public void visit(LongValue longValue) {
        map.put(longValue.getClass().getName(), longValue.getValue());
    }
}
